/*
 * nalu.h
 *
 *  Created on: 9 févr. 2011
 *      Author: aurelien
 */

#ifndef NALU_H_
#define NALU_H_

typedef unsigned char byte;

/* NAL types */
typedef enum
{
	/* Classic NAL types */
	UNSPECIFIED     = 0,
	NON_IDR_SLICE   = 1,
	SLICE_PARTA     = 2,
	SLICE_PARTB     = 3,
	SLICE_PARTC     = 4,
	IDR_SLICE       = 5,
	SEI             = 6,
	SPS             = 7,
	PPS             = 8,
	AU_DELIMITER    = 9,
	END_OF_SEQ      = 10,
	END_OF_STREAM   = 11,
	FILLER_DATA     = 12,
	/* Extension NAL types */
	SPS_EXTENTION   = 13,
	PREFIX_NALU     = 14,
	SUBSET_SPS      = 15,
	NON_PART_SLICE  = 19,
	SLICE_LAYER_EXT = 20
} NaluType;

/* 1 byte : NAL classic header */
typedef struct nal_unit_header
{
	unsigned int forbidden_zero_bit			: 1 ;
	unsigned int nri						: 2 ;
	unsigned int type						: 5 ;
} Nalu_Hdr;

/* 3 bytes : SVC/MVC NAL header extension */
typedef struct nal_unit_header_svc_extension
{
	unsigned int svc_extension_flag			: 1 ;	// reserved_one_bit : 1 - SVC (Annex G.); 0 - MVC (Annex H.)
	unsigned int idr_flag					: 1 ;	// instantaneous decoding refresh (IDR) layer representation or not.
	unsigned int priority_id				: 6 ;	// priority identifier for the NAL unit. Lower value == higher priority.
	unsigned int no_inter_layer_pred_flag	: 1 ;	// inter-layer prediction may be used for decoding the coded slice or not.	(i.e. size level)
	unsigned int dependency_id				: 3 ;	// inter-layer coding dependency level of a layer representation.			(i.e. quality level)
	unsigned int quality_id					: 4 ;	// quality level of an MGS layer representation.							(i.e. frame rate level)
	unsigned int temporal_id				: 3 ;	// temporal level of a layer representation.
	unsigned int use_ref_base_pic_flag		: 1 ;	// if 1, reference base pictures are used during the inter prediction process.
	unsigned int discardable_flag			: 1 ;	// if 1, NALU can be discarded without risking the integrity of layers with higher dependency_id values.
	unsigned int output_flag				: 1 ;	// see annexe C of ITU-T Recommendation H.264, "Advanced video coding for generic audiovisual services".
	unsigned int reserved_three_2bits		: 2 ;	// must be "11" (in binary form), ignored by decoder.
} Nalu_SvcExtensionHdr;

/* svc NAL unit structure */
typedef struct nal_unit_svc
{
	Nalu_Hdr *nalu_hdr;
	Nalu_SvcExtensionHdr *nalu_svc_hdr;
	char *payload;
} Nalu_svc;

/* Contains the svc NAL unit and its layer. */
typedef struct nalu_and_param
{
	Nalu_svc *nalu;
	Layer layer;
} Nalu_info;

/* Layer structure. */
typedef struct layer
{
	int DqId;
	int temporal_id;
} Layer;

#endif /* NALU_H_ */
